package com.aloda.controller.admin;

import cn.hutool.core.bean.BeanUtil;
import com.aloda.annotation.AdminAuthCheck;
import com.aloda.annotation.OperateLogAnno;
import com.aloda.query.OpLogPageDTO;
import com.aloda.result.PageResult;
import com.aloda.result.Result;
import com.aloda.service.OperateLogService;
import com.aloda.vo.OpLogVO;
import jakarta.annotation.Resource;
import jakarta.servlet.http.HttpServletResponse;
import org.springframework.web.bind.annotation.*;

import java.util.List;


@RestController
@RequestMapping("/admin/oplog")
public class OperateLogController {

    @Resource
    private OperateLogService operateLogService;

    /**
     * 分页查询
     * @param opLogPageDTO
     * @return
     */
    @AdminAuthCheck
    @PostMapping("/page")
    public Result<PageResult<OpLogVO>> pageQuery(@RequestBody OpLogPageDTO opLogPageDTO) {
        PageResult<OpLogVO> pageResult = operateLogService.pageQuery(opLogPageDTO);
        return Result.success(pageResult);
    }

    /**
     * 通过id查询日志
     * @param id
     * @return
     */
    @AdminAuthCheck
    @GetMapping("/{id}")
    public Result<OpLogVO> getById(@PathVariable Long id) {
        return Result.success(BeanUtil.copyProperties(operateLogService.getById(id),OpLogVO.class));
    }

    /**
     * 删除日志
     * @param ids
     * @return
     */
    @OperateLogAnno(category = "删除日志")
    @AdminAuthCheck
    @DeleteMapping
    public Result delete(@RequestBody List<Long> ids) {
        return Result.success(operateLogService.removeBatchByIds(ids));
    }

    /**
     * 导出操作日志表格信息
     * @param response
     * @param ids
     */
    @OperateLogAnno(category = "导出操作日志表格")
    @AdminAuthCheck
    @PostMapping("/export")
    public void exportOpLogToExcel(HttpServletResponse response, @RequestBody List<Long> ids) {
        operateLogService.exportOpLogToExcel(response,ids);
    }
}
